package top.lyjwn.todo.aop.log.http;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.MessageFormat;
import java.time.Duration;

public interface HttpLogHandle {

    Logger logger = LoggerFactory.getLogger(HttpLogHandle.class);

    default Logger getLogger()
    {
        return logger;
    }

    default void write(HttpLogE log) {
        getLogger().info("""
                [Request Time]    : {}
                [HTTP Method]     : {}
                [Request URL]     : {}
                [Token]           : {}
                [Client IP]       : {}
                [Request Params]  : {}
                [Response Status] : {}
                [Response Time]   : {}
                [Response Use Time]   : {}ms
                [Response Data]   : {}
                """, log.getBeginTime(), log.getMethod(), log.getUrl(), log.getToken(), log.getIp(),log.getRequestContent(),log.getResponseStatus(),log.getEndTime(), Duration.between(log.getBeginTime(), log.getEndTime()).toMinutes(),log.getResponseContent());
        ;
    }

    default void in(String log) {
        getLogger().info(log);
    }

    default void out(String log) {
        getLogger().info(log);
    }
}
